package com.java.tutorials.jdk7.jdk7;
import java.io.File;
/**
 * Created by xuzhike on 2016/1/27.
 * http://www.java2s.com/Code/Java/JDK-7/Redirectinginputandoutputfromoperatingsystemsprocesses.htm
 * Redirecting input and output from operating systems processes
 */
public class Redirectinginputandoutputfromoperatingsystemsprocesses {
    public static void main(String[] args) throws Exception {
        File commands = new File("C:/Projects/ProcessCommands.txt");
        File output = new File("C:/Projects/ProcessLog.txt");
        File errors = new File("C:/Projects/ErrorLog.txt");

        ProcessBuilder pb = new ProcessBuilder("ipconfig -all");
//        pb.command("ping www.oschina.net");
        System.out.println(pb.redirectInput().toString());
        System.out.println(pb.redirectOutput().toString());
        System.out.println(pb.redirectError().toString());

        pb.redirectInput(commands);
        pb.redirectError(errors);
        pb.redirectOutput(output);
        System.out.println(pb.redirectInput().toString());
        System.out.println(pb.redirectOutput().toString());
        System.out.println(pb.redirectError().toString());

        pb.start();
    }
}
